import { articleApi } from '@/api/news'
import React, { useEffect, useState } from 'react'
import { useNavigate } from 'react-router-dom';

function Article() {
    // const [page, setPage] = useState(1)
    const nav=useNavigate()
    const [list, setlist] = useState([]);
    const getData = async () => {
        const res = await articleApi()
        console.log(res.rows)
        setlist(list.concat(res.rows));
    }
    useEffect(() => {
        getData()
    }, [])
    const toDetail=(id)=>{
        nav(`/detail/${id}`,{state:id})
    }
    return (
        <div>{
            list.map((v, i) => {
                return <div key={i} onClick={()=>toDetail(v.id)}>
                    {v.content}
                </div>
            })
        }</div>
    )
}

export default Article